<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>全选反选</title>
	</head>
	<body>
		<input type="checkbox" id="all"  />全选<br />
		<hr />
		<input type="checkbox" class="box" />电脑<br>
		<input type="checkbox" class="box" />手机<br>
		<input type="checkbox" class="box"/>平板<br>
		<script type="text/javascript">
			var all=document.getElementById('all');
			var box=document.getElementsByClassName('box');
			//全选框添加点击事件
			/*all.onclick=function(){
				for(var i=0;i<box.length;i++){
					box[i].checked=event.target.checked;
					
				}
			};*/
			//事件监听:点击all 执行fun函数
			all.addEventListener('click',fun,false);
			function fun(){
				for (var i=0;i<box.length;i++) {
					box[i].checked=event.target.checked;
				}
			}
		</script>
	</body>
</html>
